﻿<style scoped>
.el-radio {
  line-height: 32px;
}
</style>
<template>
  <div class="app-container">
    <div class="filter-title">
      <el-form label-position="right" label-width="80px">
        <el-form-item :label="$t('equipment.code')+' :'">
          <el-input
            v-model="listQuery.code"
            style="width: 150px"
            class="filter-item"
            :placeholder="$t('equipment.code')"
            @keyup.enter.native="handleFilter"
          ></el-input>
        </el-form-item>
        <el-form-item :label="$t('public.linkman')+' :'">
          <el-input
            v-model="listQuery.correlation"
            style="width: 150px"
            class="filter-item"
            :placeholder="$t('public.linkman')"
            @keyup.enter.native="handleFilter"
          ></el-input>
        </el-form-item>
        <el-form-item :label="$t('error.type')+' :'">
          <el-select
            v-model="listQuery.type"
            clearable
            style="width: 150px"
            class="filter-item"
            :placeholder="$t('error.type')"
          >
            <el-option
              v-for="item in typeOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-button
          style="margin-left:20px"
          class="filter-item"
          type="primary"
          icon="el-icon-search"
          @click="handleFilter"
        >{{ $t('table.search') }}</el-button>
        <el-button
          v-if="permission.add"
          style="margin-left: 10px; float:right"
          class="filter-item"
          type="primary"
          icon="el-icon-edit"
          @click="handleCreate"
        >{{ $t('table.add') }}</el-button>
        <el-button
          style="margin-left: 10px"
          class="filter-item"
          type="primary"
          @click="handleRefresh"
        >{{ $t('table.refresh') }}</el-button>
        <div v-show="!showSearchItem" class="showDown" @click="showSearchItem = true">
          <i class="el-icon-d-arrow-right"></i>
        </div>
        <div v-show="showSearchItem" class="showUp" @click="showSearchItem = false">
          <i class="el-icon-d-arrow-left"></i>
        </div>
      </el-form>
    </div>
    <div v-show="showSearchItem" class="filter-container">
      <el-form label-position="right" label-width="80px">
        <el-form-item :label="$t('error.time')+' :'">
          <div class="filter-item">
            <el-date-picker
              v-model="listQuery.startEventTime"
              :picker-options="pickerOptionsB"
              type="date"
              :placeholder="$t('error.starTime')"
              value-format="yyyy-MM-dd HH:mm:ss"
            ></el-date-picker>
          </div>
          <div class="filter-item">
            <el-date-picker
              v-model="listQuery.endEventTime"
              :picker-options="pickerOptionsE"
              type="date"
              :placeholder="$t('error.endTime')"
              value-format="yyyy-MM-dd HH:mm:ss"
            ></el-date-picker>
          </div>
        </el-form-item>
      </el-form>
    </div>
    <el-table
      :key="tableKey"
      v-loading="listLoading"
      :data="list"
      element-loading-text="拼命加载中"
      element-loading-spinner="el-icon-loading"
      element-loading-background="rgba(255,255,255,0.2)"
      border
      fit
      highlight-current-row
      style="width: 100%min-height:1000px"
    >
      <el-table-column fixed="left" align="center" :label="$t('table.id')" width="65">
        <template slot-scope="scope">
          <span>{{ (listQuery.page-1)*listQuery.limit+scope.$index+1 }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" :label="$t('equipment.id')">
        <template slot-scope="scope">
          <span>{{ scope.row.equipment_id }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" :label="$t('equipment.ip')">
        <template slot-scope="scope">
          <span>{{ scope.row.ip }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" show-overflow-tooltip :label="$t('equipment.code')">
        <template slot-scope="scope">
          <span>{{ scope.row.equipment_code }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" :label="$t('public.linkman')">
        <template slot-scope="scope">
          <span>{{ scope.row.correlation_person }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" :label="$t('error.type')">
        <template slot-scope="scope">
          <span>{{ typeEstimation(scope.row.type) }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" :label="$t('error.describe')">
        <template slot-scope="scope">
          <span>{{ scope.row.event_describe }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" :label="$t('public.status')">
        <template slot-scope="scope">
          <span
            :class="statusColor(scope.row.check_status)"
          >{{ statusEsSecond(scope.row.check_status) }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" show-overflow-tooltip :label="$t('error.time')">
        <template slot-scope="scope">
          <span>{{ scope.row.event_time }}</span>
        </template>
      </el-table-column>
      <el-table-column
        fixed="right"
        align="center"
        :label="$t('table.actions')"
        :width="operWidth"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            type="primary"
            size="mini"
            @click="handleRead(scope.row)"
          >{{ $t('table.read') }}</el-button>
          <el-button
            v-if="permission.update"
            type="primary"
            size="mini"
            :disabled="scope.row.check_status !== 1?false:true"
            @click="handleUpdate(scope.row)"
          >{{ $t('table.edit') }}</el-button>
          <el-button
            v-if="permission.del"
            type="primary"
            size="mini"
            :disabled="scope.row.check_status !== 1?false:true"
            @click="handleReview(scope.row)"
          >{{ $t('table.review') }}</el-button>
          <el-button
            v-if="permission.del"
            size="mini"
            type="danger"
            :disabled="scope.row.check_status !== 1?false:true"
            @click="handleModifyStatus(scope.row,'deleted')"
          >{{ $t('table.delete') }}</el-button>
        </template>
      </el-table-column>
    </el-table>

    <div class="pagination-container">
      <el-pagination
        background
        :current-page="listQuery.page"
        :page-sizes="[10,20,30,50]"
        :page-size="listQuery.limit"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      ></el-pagination>
    </div>
    <!-- 编辑 -->
    <el-dialog :title="textMap[dialogStatus]" :visible.sync="dialogFormVisible">
      <el-form
        ref="dataForm"
        :rules="rules"
        :model="temp"
        label-position="right"
        label-width="20%"
        style="margin-left:120px"
        size="small"
      >
        <el-form-item v-if="dialogStatus=='review'" :label="$t('equipment.code')+' :'">
          <span>{{ temp.equipment_code }}</span>
        </el-form-item>
        <el-form-item v-else :label="$t('equipment.code')+' :'" prop="equipment_id">
          <select-page
            :id="temp.equipment_id"
            :name="temp.equipment_code"
            style="width:300px"
            placeholder="请选择广告机"
            key-field="id"
            show-field="name"
            :data="equipmentOptions"
            :count="equipmentCount"
            :page-size="pageSize"
            @getList="getEquipmentList"
            @values="getEquipmentid"
          ></select-page>
        </el-form-item>
        <el-form-item v-if="dialogStatus!='create'" :label="$t('equipment.ip')">
          <span>{{ temp.ip }}</span>
        </el-form-item>
        <el-form-item v-if="dialogStatus=='review'" :label="$t('public.linkman')+' :'">
          <span>{{ temp.correlation_person }}</span>
        </el-form-item>
        <el-form-item
          v-else
          :label="$t('public.linkman')+' :'"
          prop="correlation_person"
        >
          <el-input v-model="temp.correlation_person"></el-input>
        </el-form-item>
        <el-form-item v-if="dialogStatus=='review'" :label="$t('equipment.personMobile')+' :'">
          <span>{{ temp.correlation_person_mobile }}</span>
        </el-form-item>
        <el-form-item
          v-else
          :label="$t('equipment.personMobile')+' :'"
          prop="correlation_person_mobile"
        >
          <el-input v-model="temp.correlation_person_mobile"></el-input>
        </el-form-item>
        <el-form-item v-if="dialogStatus=='review'" :label="$t('error.type')+' :'">
          <span>{{ typeEstimation(temp.type) }}</span>
        </el-form-item>
        <el-form-item v-else :label="$t('error.type')+' :'" prop="type">
          <el-radio-group v-model="temp.type">
            <el-radio :label="1">开机</el-radio>
            <el-radio :label="2">关机</el-radio>
            <el-radio :label="3">网络断开</el-radio>
            <el-radio :label="4">APP启动</el-radio>
            <el-radio :label="5">app关闭</el-radio>
            <el-radio :label="6">结束播放</el-radio>
            <el-radio :label="7">开始播放</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item v-if="dialogStatus=='review'" :label="$t('error.describe')+' :'">
          <span>{{ temp.event_describe }}</span>
        </el-form-item>
        <el-form-item v-else :label="$t('error.describe')+' :'" prop="event_describe">
          <el-input v-model="temp.event_describe" type="textarea"></el-input>
        </el-form-item>
        <el-form-item
          v-if="dialogStatus=='review'"
          :label="$t('public.status')+' :'"
          prop="check_status"
        >
          <el-radio-group v-model="temp.check_status">
            <el-radio :label="0" disabled>审核中</el-radio>
            <el-radio :label="1">审核通过</el-radio>
            <el-radio :label="2">未通过</el-radio>
            <!-- <el-radio :label="3">禁用</el-radio> -->
          </el-radio-group>
        </el-form-item>
        <el-form-item v-else-if="dialogStatus=='edit'" :label="$t('public.status')+' :'">
          <span>{{ statusEsSecond(temp.check_status) }}</span>
        </el-form-item>
        <el-form-item
          v-if="dialogStatus!=='create' && temp.check_status === 2"
          :label="$t('public.auditOpinion')+' :'"
          prop="remark"
        >
          <el-input v-if="dialogStatus==='review'" v-model="temp.remark" type="textarea"></el-input>
          <span v-else>{{ temp.remark }}</span>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">{{ $t('table.cancel') }}</el-button>
        <el-button
          v-if="dialogStatus=='create'"
          type="primary"
          :disabled="!createDisabled"
          @click="createData"
        >{{ $t('table.confirm') }}</el-button>
        <el-button
          v-else-if="dialogStatus=='review'"
          type="primary"
          :disabled="!reviewDisabled"
          @click="reviewData"
        >{{ $t('table.confirm') }}</el-button>
        <el-button
          v-else
          type="primary"
          :disabled="!updateDisabled"
          @click="updateData()"
        >{{ $t('table.confirm') }}</el-button>
      </div>
    </el-dialog>

    <!-- 查看 -->
    <el-dialog :title="textMap[dialogStatus]" :visible.sync="dialogFormRead">
      <el-form :model="temp" label-position="right" label-width="40%" style="margin-left:120px">
        <el-form-item :label="$t('equipment.id')+' :'">
          <span>{{ temp.equipment_id }}</span>
        </el-form-item>
        <el-form-item :label="$t('equipment.code')+' :'">
          <span>{{ temp.equipment_code }}</span>
        </el-form-item>
        <el-form-item :label="$t('equipment.ip')+' :'">
          <span>{{ temp.ip }}</span>
        </el-form-item>
        <el-form-item :label="$t('public.linkman')+' :'">
          <span>{{ temp.correlation_person }}</span>
        </el-form-item>
        <el-form-item :label="$t('equipment.personMobile')+' :'">
          <span>{{ temp.correlation_person_mobile }}</span>
        </el-form-item>
        <el-form-item :label="$t('error.type')+' :'">
          <span>{{ typeEstimation(temp.type) }}</span>
        </el-form-item>
        <el-form-item :label="$t('error.describe')+' :'">
          <span>{{ temp.event_describe }}</span>
        </el-form-item>
        <el-form-item :label="$t('public.status')+' :'">
          <span>{{ statusEsSecond(temp.check_status) }}</span>
        </el-form-item>
        <el-form-item
          v-if="temp.check_status === 2"
          :label="$t('public.auditOpinion')+' :'"
          prop="remark"
        >
          <span>{{ temp.remark }}</span>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>
<script>
import selectPage from "@/views/select/SelectPage"; // 分页选择控件

export default {
  name: "EquipmentLog",
  components: {
    "select-page": selectPage
  },
  data() {
    const correlationPerson = (rule, value, callback) => {
      // return false
      if (value.length > 0) {
        if (value.length > 16) {
          callback(new Error("名称长度不能大于16个字符"));
        } else {
          var reg = /^[\u4e00-\u9fffa-z-A-Z]+$/; /* 定义验证表达式 */
          if (reg.test(value)) {
            /* 进行验证 */
            callback();
          } else {
            callback(new Error("姓名只能包含汉字、英文"));
          }
        }
      } else {
        callback(new Error("请填写姓名"));
      }
    };
    const mobile = (rule, value, callback) => {
      // return false
      if (value.length > 0) {
        var reg = /^((0\d{2,3}-\d{7,8})|(1[3584]\d{9}))$/; /* 定义验证表达式 */
        if (reg.test(value)) {
          /* 进行验证 */
          callback();
        } else {
          callback(new Error("请输入正确的联系电话"));
        }
      } else {
        callback(new Error("请填写联系电话"));
      }
    };
    const remark = (rule, value, callback) => {
      if (value) {
        if (value.length <= 0) {
          callback(new Error("请输入审核意见"));
        } else if (value.length > 300) {
          callback(new Error("审核意见不能超过300个字符"));
        } else {
          callback();
        }
      } else {
        callback(new Error("请输入审核意见"));
      }
    };
    return {
      showSearchItem: false,
      tableKey: 0,
      list: null,
      total: null,
      regionType: null,
      regionId: null,
      listLoading: true,
      statusOptions: [
        {
          value: 1,
          label: "审核中"
        },
        {
          value: 2,
          label: "审核通过"
        },
        {
          value: 3,
          label: "未通过"
        },
        {
          value: 4,
          label: "禁用"
        }
      ],
      typeOptions: [
        {
          value: 1,
          label: "开机"
        },
        {
          value: 2,
          label: "关机"
        },
        {
          value: 3,
          label: "网络断开"
        },
        {
          value: 4,
          label: "APP启动"
        },
        {
          value: 5,
          label: "APP关闭"
        },
        {
          value: 6,
          label: "结束播放"
        },
        {
          value: 7,
          label: "开始播放"
        },
        {
          value: 8,
          label: "播放异常"
        }
      ],
      listQuery: {
        page: 1,
        limit: 20,
        code: "",
        correlation: "",
        type: "",
        startEventTime: "",
        endEventTime: ""
      },
      temp: {
        id: undefined,
        equipment_id: "",
        equipment_code: "",
        correlation_person: "",
        correlation_person_mobile: "",
        type: "",
        event_describe: ""
      },
      dialogFormVisible: false,
      dialogFormRead: false,
      dialogStatus: "",
      textMap: {
        edit: "编辑",
        create: "添加",
        review: "审核",
        read: "查看"
      },
      rules: {
        equipment_id: [
          { required: true, message: "请填选择设备编号", trigger: "blur" }
        ],
        correlation_person: [
          { required: true, trigger: "blur", validator: correlationPerson }
        ],
        correlation_person_mobile: [
          { required: true, trigger: "blur", validator: mobile }
        ],
        type: [
          { required: true, message: "请选择故障类型", trigger: "change" }
        ],
        event_describe: [
          { required: true, message: "请填写故障描述", trigger: "blur" }
        ],
        check_status: [
          { required: true, message: "请审核", trigger: "change" }
        ],
        remark: [{ required: true, trigger: "blur", validator: remark }]
      },
      createDisabled: true,
      updateDisabled: true,
      reviewDisabled: true,
      loading: false,
      equipmentOptions: [],
      equipmentCount: undefined,
      pageSize: 20,
      permission: {
        add: false,
        del: false,
        update: false
      },
      pickerOptionsB: {
        // 限制时间
        // selectableRange: ['22:00:00 - 23:59:59','00:00:00 - 02:00:00'],
        // 限制日期
        disabledDate: this.disabledDateB
      },
      pickerOptionsE: {
        disabledDate: this.disabledDateE
      }
    };
  },
  computed: {
    operWidth: function() {
      let itemCount = 1;
      if (this.permission.del) {
        itemCount += 2;
      }
      if (this.permission.update) {
        itemCount += 1;
      }
      return itemCount * 80 + "px";
    }
  },
  created() {
    if (this.$store.state.permission.jurisdiction === "*") {
      this.permission.add = true;
      this.permission.update = true;
      this.permission.del = true;
    } else {
      const jurisdiction = this.$store.state.permission.jurisdiction.split(",");
      jurisdiction.forEach(element => {
        const id = parseInt(element);
        if (id === 149) {
          this.permission.add = true;
        }
        if (id === 150) {
          this.permission.del = true;
        } else if (id === 151) {
          this.permission.update = true;
        }
      });
    }
    this.regionId = this.$store.state.user.id;
    this.regionType = this.$store.state.user.regionType;
    this.getList();
  },
  methods: {
    disabledDateB(time) {
      if (this.listQuery.endEventTime) {
        return (
          time.getTime() >
          new Date(this.listQuery.endEventTime).getTime() +
            24 * 3600 * 1000 -
            8.64e7
        );
      }
    },
    disabledDateE(time) {
      if (this.listQuery.startEventTime) {
        return (
          time.getTime() <
          new Date(this.listQuery.startEventTime).getTime() - 8.64e6
        );
      }
    },
    getEquipmentList(pageNumber = 1, search = "") {
      this.getEquipment(pageNumber, search);
    },
    getEquipmentid(data) {
      if (data.length > 0) {
        this.temp.equipment_id = data[0].id;
        this.temp.equipment_code = data[0].name;
      } else {
        this.temp.equipment_id = undefined;
        this.temp.equipment_code = "";
      }
    },
    getList() {
      this.listLoading = true;
      const data = {
        rows: this.listQuery.limit,
        page: this.listQuery.page
      };
      if (this.listQuery.code) {
        data["code"] = this.listQuery.code;
      }
      if (this.listQuery.correlation) {
        data["correlation"] = this.listQuery.correlation;
      }
      if (this.listQuery.type) {
        data["type"] = this.listQuery.type;
      }
      if (this.listQuery.eventTime) {
        data["startEventTime"] = this.listQuery.eventTime[0];
        const date = new Date(this.listQuery.eventTime[1]);
        data["endEventTime"] = this.timestampToTime(
          date.getTime() + (60 * 60 * 24 * 1000 - 1)
        );
      }
      if (this.listQuery.startEventTime) {
        data["startEventTime"] = this.listQuery.startEventTime;
      }
      if (this.listQuery.endEventTime) {
        const date = new Date(this.listQuery.endEventTime);
        data["endEventTime"] = this.timestampToTime(
          date.getTime() + (60 * 60 * 24 * 1000 - 1)
        );
      }
      const logIndexPath = {
        // 获取智能广告终端故障列表
        company: "STQ",
        api: "pc_log_index",
        version: "1.0",
        data: data
      };
      this.socketApi.sendSock(JSON.stringify(logIndexPath), res => {
        if (res) {
          this.socketData(res);
        }
      });
    },
    handleFilter() {
      this.listQuery.page = 1;
      this.getList();
    },
    handleSizeChange(val) {
      this.listQuery.limit = val;
      this.getList();
    },
    handleCurrentChange(val) {
      this.listQuery.page = val;
      this.getList();
    },
    handleModifyStatus(row) {
      this.$confirm("此操作将永久删除该故障日志, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          const logDeletePath = {
            company: "STQ",
            api: "pc_log_delete",
            version: "1.0",
            data: {
              id: row.id
            }
          };
          this.socketApi.sendSock(JSON.stringify(logDeletePath), res => {
            if (res) {
              this.socketData(res);
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    },
    resetTemp() {
      this.temp = {
        id: undefined,
        equipment_id: "",
        equipment_code: "",
        correlation_person: "",
        correlation_person_mobile: "",
        type: "",
        event_describe: ""
      };
    },
    resetArea() {
      this.areaOptions = [];
      this.temp.region_id = "";
    },
    handleRefresh() {
      this.listQuery = {
        page: 1,
        limit: 20,
        code: "",
        correlation: "",
        type: "",
        startEventTime: "",
        endEventTime: ""
      };
      this.getList();
    },
    handleReview(row) {
      // 打开审核弹窗
      this.temp = Object.assign({}, row); // copy obj
      this.dialogStatus = "review";
      this.dialogFormVisible = true;
      this.$nextTick(() => {
        this.$refs["dataForm"].clearValidate();
      });
    },
    handleUpdate(row) {
      // 打开编辑弹窗
      this.temp = Object.assign({}, row); // copy obj
      this.temp.type = parseInt(this.temp.type);
      this.dialogStatus = "edit";
      this.dialogFormVisible = true;
      this.$nextTick(() => {
        this.$refs["dataForm"].clearValidate();
      });
    },
    handleRead(row) {
      // 打开查看弹窗
      this.temp = Object.assign({}, row); // copy obj
      this.dialogStatus = "read";
      this.dialogFormRead = true;
    },
    handleCreate() {
      // 打开添加弹窗
      this.resetTemp();
      this.dialogStatus = "create";
      this.dialogFormVisible = true;
      this.$nextTick(() => {
        this.$refs["dataForm"].clearValidate();
      });
    },
    createData(row) {
      // 添加智能终端设备故障日志
      this.$refs["dataForm"].validate(valid => {
        if (valid) {
          if (this.createDisabled) {
            this.createDisabled = false;
            const data = {
              equipment_id: this.temp.equipment_id,
              equipment_code: this.temp.equipment_code,
              correlation_person: this.temp.correlation_person,
              correlation_person_mobile: this.temp.correlation_person_mobile,
              type: this.temp.type,
              event_describe: this.temp.event_describe
            };
            const logAddPath = {
              company: "STQ",
              api: "pc_log_add",
              version: "1.0",
              data: data
            };
            this.socketApi.sendSock(JSON.stringify(logAddPath), res => {
              if (res) {
                this.socketData(res);
              }
              setTimeout(() => {
                this.createDisabled = true;
              }, 1000);
            });
          }
        }
      });
    },
    reviewData(row) {
      // 故障审核
      this.$refs["dataForm"].validate(valid => {
        if (valid) {
          if (this.updateDisabled) {
            this.reviewDisabled = false;
            const data = {
              id: this.temp.id,
              check_status: this.temp.check_status
            };
            if (this.temp.remark) {
              data["remark"] = this.temp.remark;
            }
            const logEditPath = {
              company: "STQ",
              api: "pc_log_edit",
              version: "1.0",
              data: data
            };
            this.socketApi.sendSock(JSON.stringify(logEditPath), res => {
              if (res) {
                this.socketData(res);
              }
              setTimeout(() => {
                this.reviewDisabled = true;
              }, 1000);
            });
          }
        }
      });
    },
    updateData() {
      // 更新智能广告终端
      this.$refs["dataForm"].validate(valid => {
        if (valid) {
          if (this.updateDisabled) {
            this.updateDisabled = false;
            const data = {
              id: this.temp.id,
              equipment_id: this.temp.equipment_id,
              equipment_code: this.temp.equipment_code,
              correlation_person: this.temp.correlation_person,
              correlation_person_mobile: this.temp.correlation_person_mobile,
              type: this.temp.type,
              event_describe: this.temp.event_describe
            };
            const logEditPath = {
              company: "STQ",
              api: "pc_log_edit",
              version: "1.0",
              data: data
            };
            this.socketApi.sendSock(JSON.stringify(logEditPath), res => {
              if (res) {
                this.socketData(res);
              }
              setTimeout(() => {
                this.updateDisabled = true;
              }, 1000);
            });
          }
        }
      });
    },
    getEquipment(pageNumber, search) {
      const getEquipmentCodePath = {
        company: "STQ",
        api: "pc_equipment_getEquipmentCode",
        version: "1.0",
        data: {
          name: search,
          page: pageNumber,
          rows: this.pageSize
        }
      };
      this.socketApi.sendSock(JSON.stringify(getEquipmentCodePath), res => {
        if (res) {
          this.socketData(res);
        }
      });
    },
    socketData(res) {
      if (res !== '{"type":"ping"}') {
        const resj = JSON.parse(res);
        if (resj.code === -1) {
          this.$message.error(resj.message);
        } else {
          if (resj.api === "pc_log_edit") {
            this.dialogFormVisible = false;
            this.getList();
            this.$notify({
              title: "成功",
              message: "更新成功",
              type: "success",
              duration: 2000
            });
          } else if (resj.api === "pc_log_delete") {
            this.getList();
            this.$message({
              type: "success",
              message: "删除成功!"
            });
          } else if (resj.api === "pc_equipment_getEquipmentCode") {
            const options = [];
            resj.data.forEach(element => {
              options.push({ id: element.id, name: element.code });
            });
            this.equipmentOptions = options;
            this.equipmentCount = resj.count;
          } else if (resj.api === "pc_log_add") {
            this.dialogFormVisible = false;
            this.getList();
            this.$notify({
              title: "成功",
              message: "添加成功",
              type: "success",
              duration: 2000
            });
          } else if (resj.api === "pc_log_index") {
            this.total = resj.count;
            this.list = resj.data;
            this.listLoading = false;
          }
        }
      }
    }
  }
};
</script>
